package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.CarDao;
import com.ChenYaRou.www.po.Car;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName CarDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/13 14:09
 * @Version 1.0
 **/
public class CarDaoImpl implements CarDao {
    @Override
    public int update(Car newCar,Car oldCar) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newCar,oldCar));

    }

    /**
     * 新建购物单
     * @param car 新购物车单
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(Car car) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(car));
    }

    /**
     * 删除购物车 未使用
     * @return
     */
    @Override
    public boolean delete() {
        return false;
    }

    /**
     * 查找car集合
     * @param car 条件car
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<Car> selectMore(Car car) throws IllegalAccessException, SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().select(car), Car.class);
    }
}
